import { InjectionKey } from "vue";
import { createStore, Store, useStore as baseUseStore } from "vuex";

import modules from "./modules";

export interface TodoItem {
  id: number;
  name: string;
  isDone: boolean;
}

// 定义vuex管理的所有state数据的类型
export interface State {
  todo: {
    todoList: TodoItem[];
  };
}

export const key: InjectionKey<Store<State>> = Symbol();

// 定义简化使用useStore的方法
export function useStore() {
  return baseUseStore(key);
}

export default createStore({
  modules,
});
